const md5 = require('md5');
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017/user_manage')
mongoose.connection.on('open',async ()=>{
    console.log('数据库连接成功');
    //初始化用户信息
    const userModel = require('./models/userModel')
    let user =await userModel.find({username:'admin'})
    // console.log(user);
    
    if(!user.length){
        let res = await userModel.create({
            username:'admin',
            pwd:md5('111111'),
            profile:'/upload/admin.png'
        })
        // console.log(res);
        for(let i = 0;i<20;i++){
            userModel.create({
                username:'user'+i,
                pwd:md5('111111'),
                profile:'/upload/admin.png'
            })
        }
    }
    
})
mongoose.connection.on('error',()=>{
    console.log('数据库连接失败');
    
})
module.exports=mongoose